<template>
  <div class="subject">
    <span>{{ item.num1 }}</span>
    <span>+</span>
    <span>{{ item.num2 }}</span>
    <span>=</span>
    <input
      type="number"
      v-model.number="sum"
    />
    <button
      @click="checkResult"
      :disabled="item.state!=='未完成'"
    >提交</button>
  </div>
</template>

<script>
export default {
  props: ["item"],
  data() {
    return {
      sum: "",
    };
  },
  methods: {
    checkResult() {
      // 判断是否没有输入内容
      if (this.sum === "") return alert("请输入答案");
      // 判断正确还是错误
      if (this.item.num1 + this.item.num2 === this.sum) {
        this.item.state = "正确";
      } else {
        this.item.state = "错误";
      }
    },
  },
};
</script>

<style scoped>
.subject {
  margin: 5px;
  padding: 5px;
  font-size: 20px;
}
.subject span {
  display: inline-block;
  text-align: center;
  width: 20px;
}
.subject input {
  width: 50px;
  height: 20px;
}
</style>